/*
 * @lc app=leetcode.cn id=338 lang=rust
 *
 * [338] 比特位计数
 */

// @lc code=start
impl Solution {
    pub fn count_bits(n: i32) -> Vec<i32> {
        let mut ret = vec![0];
        if n == 0 {
            return ret;
        }

        let mut len = ret.len() as i32;
        while len < n+1 {

            let mut v2:Vec<i32> = ret.iter().map(|x| x + 1).collect();
            ret.append(&mut v2);

            len = ret.len() as i32;
        }

        return ret[(0 as usize)..((n+1) as usize)].to_vec();
        
    }

    
}
// @lc code=end

